#include once "mud-gui/ui.bi"
#include once "mud-gui/gclass.bi"
#include once "mud-gui/util.bi"
namespace ui
	
const as widgetID ContainerWidgetID = &HFFFFFFFF 'i reccomend starting from the top
'with widgetIDs just to be safe, official ones start at the bottom.

gclass(Container)


	declare constructor ( byval parent as BaseWidget ptr = 0 )
	declare sub setWidth( byval w as integer )
	declare sub setHeight( byval h as integer )
	declare sub setLocation( byval x as integer, byval y as integer)
	
	declare static function EventHandler( byval ref as BaseWidget ptr, byval e as _GUI_EVENT_ ptr ) as integer
	'Type is simple so we don't need our own destructor, see Constructor below
	'declare static function Destroy( byval ref as BaseWidget ptr )
	declare STATIC_SLOT(PaintEvent)
	
	
endgclass

constructor Container( byval parent as BaseWidget ptr = 0 )
	if parent <> 0 then
		SetParent(parent)
	end if
	(BaseObject).id = ContainerWidgetID
	(BaseObject).cl = layout_t.noLayout
	connectSignal(@this,repaint,Container.PaintEvent)
		
end constructor

sub Container.setWidth( byval w as integer )
	(BaseObject).width = w
end sub

sub Container.setHeight( byval h as integer )
	(BaseObject).height = h
end sub

sub Container.setLocation( byval x as integer, byval y as integer )
	(BaseObject).x = x
	(BaseObject).y = y
end sub

STATIC_SLOT(Container.PaintEvent)
	if ref->buffer = 0 then
		ref->buffer = imagecreate(ref->width, ref->height)
		paint ref->buffer,(1,1),&hFFC9C9C9
        line ref->buffer,(1,1)-(ref->width -1,ref->height-1), &hFF000000, B
	End If
	
	put (ref->x, ref->y), ref->buffer, PSET
	return 0
ENDSLOT

end namespace

using ui
var x = new Container
x->setLocation(10,20)
x->setWidth(50)
x->setHeight(50)
'Defaults to 320x240x32
if initScreen("Custom Widget Example") = 1 then 
end runGUI(toBaseWidget(x)) 'returns any error codes
'no need to free the memory, runGUI deletes the main widget at program end which
'deletes any children it had.
'other functions to checkout: 
'in ui.bi:
'addTimer() - allows a widget to recieve an event(s) at certain time periods
'setFocus() - a widget must have focus to recieve keyboard events
else
print "Unable to set screenmode"
end if
